<template>
  <div v-loading="loading" class="content-detail" :style="{ height: props.height + 'px' }">
    <template v-if="detailData">
      <div class="content-view" :style="{ height: props.height - 20 + 'px' }">
        <div class="content-scroll" v-html="detailData.content"></div>
      </div>
    </template>
    <el-empty v-else description="暂无数据" />
  </div>
</template>

<script setup lang="ts">
import { ref, watch } from 'vue'
import { pageNoteModel, type PageNote } from './pageNoteModel'

const props = withDefaults(defineProps<{
  id?: number
  height?: number
}>(), {
  height: 256
})

const loading = ref(false)
const detailData = ref<PageNote>()

// 获取详情数据
const getDetail = async () => {
  if (!props.id) return
  
  try {
    loading.value = true
    const res = await pageNoteModel.getPageNoteDetail(props.id)
    detailData.value = res
  } catch (error) {
    console.error('获取详情失败:', error)
  } finally {
    loading.value = false
  }
}

// 监听 id 变化
watch(() => props.id, (id) => {
  if (id) {
    getDetail()
  }
}, { immediate: true })
</script>

<style scoped>
.content-detail {
  padding: 10px;
  min-height: 100px;
  transition: height 0.3s ease;
  width: 100%;
  box-sizing: border-box;
}

.content-view {
  padding: 15px;
  background-color: #fff;
  border: 1px solid #dcdfe6;
  border-radius: 4px;
  overflow: hidden;
  transition: height 0.3s ease;
  width: 100%;
  box-sizing: border-box;
}

.content-scroll {
  height: 100%;
  overflow-y: auto;
  padding-right: 10px;
  width: 100%;
  box-sizing: border-box;
}

/* 自定义滚动条样式 */
.content-scroll::-webkit-scrollbar {
  width: 6px;
}

.content-scroll::-webkit-scrollbar-thumb {
  background-color: #c0c4cc;
  border-radius: 3px;
}

.content-scroll::-webkit-scrollbar-track {
  background-color: #f5f7fa;
}

/* 富文本内容样式 */
.content-scroll :deep(h1) {
  font-size: 24px;
  margin: 16px 0;
}

.content-scroll :deep(h2) {
  font-size: 20px;
  margin: 14px 0;
}

.content-scroll :deep(h3) {
  font-size: 18px;
  margin: 12px 0;
}

.content-scroll :deep(p) {
  margin: 8px 0;
}

.content-scroll :deep(ul), .content-scroll :deep(ol) {
  padding-left: 20px;
  margin: 8px 0;
}

.content-scroll :deep(li) {
  margin: 4px 0;
}

.content-scroll :deep(blockquote) {
  margin: 8px 0;
  padding: 8px 16px;
  border-left: 4px solid #dcdfe6;
  background-color: #f5f7fa;
}

.content-scroll :deep(pre) {
  margin: 8px 0;
  padding: 12px;
  background-color: #f5f7fa;
  border-radius: 4px;
  overflow-x: auto;
}

.content-scroll :deep(code) {
  font-family: Consolas, Monaco, 'Andale Mono', monospace;
  background-color: #f5f7fa;
  padding: 2px 4px;
  border-radius: 3px;
}

.content-scroll :deep(img) {
  max-width: 100%;
  height: auto;
  margin: 8px 0;
}

.content-scroll :deep(a) {
  color: #409eff;
  text-decoration: none;
}

.content-scroll :deep(a:hover) {
  text-decoration: underline;
}

.content-scroll :deep(table) {
  border-collapse: collapse;
  width: 100%;
  margin: 8px 0;
}

.content-scroll :deep(th), .content-scroll :deep(td) {
  border: 1px solid #dcdfe6;
  padding: 8px;
  text-align: left;
}

.content-scroll :deep(th) {
  background-color: #f5f7fa;
  font-weight: bold;
}
</style> 